'use strict';
const {parseTime} = require("../../utils");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, BIGINT } = app.Sequelize;
    const OrderLog = app.model.define(
        'OrderLog',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            order_id: {type: INTEGER, allowNull: false, comment: '订单ID'},
            order_no: {type: STRING(255), allowNull: false, comment: '订单号'},
            action: {type: STRING(100), allowNull: false, comment: '操作类型：create-创建订单，pay-支付，ship-发货，complete-完成，cancel-取消，refund-退款等'},
            status_from: {type: STRING(50), allowNull: true, comment: '操作前状态'},
            status_to: {type: STRING(50), allowNull: true, comment: '操作后状态'},
            remark: {type: STRING(500), allowNull: true, comment: '操作备注'},
            operator: {type: STRING(100), allowNull: true, comment: '操作人'},
            operator_id: {type: BIGINT, allowNull: true, comment: '操作人ID'},
            ip: {type: STRING(50), allowNull: true, comment: '操作IP'},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'order_log',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    OrderLog.associate = function() {
        app.model.Business.OrderLog.belongsTo(app.model.Business.Order, {as: 'order', foreignKey: 'order_id'});
    }
    
    return OrderLog;
}; 